package asynqQueue

import (
	"github.com/gogf/gf/database/gredis"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/util/gconv"
	"github.com/hibiken/asynq"
)

type OrderTopicType uint8

const (
	CloseNoPayOrder OrderTopicType = iota // 关闭未支付订单
	ConfirmOrder                          // 发货后 14 天，自动确认收货
	EvaluatedOrder                        // 订单完成后 7 天，自动好评
)

var OrderTopicName = map[OrderTopicType]string{
	CloseNoPayOrder: "CloseNoPayOrder",
	ConfirmOrder:    "ConfirmOrder",
	EvaluatedOrder:  "EvaluatedOrder",
}

func GetRedisClientOpt() asynq.RedisClientOpt {
	redisConfig, err := gredis.ConfigFromStr(g.Cfg().GetString("redis.queue"))
	if err != nil {
		panic(err)
	}
	return asynq.RedisClientOpt{
		Addr:     redisConfig.Host + ":" + gconv.String(redisConfig.Port),
		Password: redisConfig.Pass,
		DB:       redisConfig.Db,
	}
}
